import {HTTP} from "@/utils/http.ts";
import {useEffect, useState} from "react";
import {OrderData} from "@/vite-env";

const useOrderData = () => {
    const [order_data, setOrderData] = useState([])

    useEffect(() => {
        async function getOrderData() {
            const res = await HTTP.post('/all_order')
            // 按照时间从早到晚排序
            res.data.sort((a: OrderData, b: OrderData) => {
                return new Date(a.time || "").getTime() - new Date(b.time || "").getTime()
            })
            setOrderData(res.data)
        }

        getOrderData()
    }, [])

    return [order_data]
}

export default useOrderData